package com.lebang.service.sys;

import com.lebang.domain.ValidConfig;
import com.lebang.domain.ValidMemberRecord;
import com.lebang.example.ValidMemberRecordExample;
import com.lebang.mapper.ValidMemberRecordMapper;
import com.lebang.model.Whether;
import com.lebang.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * valid_member_record
 *
 * @Author hwq
 * @Date 2020-08-17
 */
@Service
public class ValidMemberRecordService extends BaseService<ValidMemberRecord, Integer, ValidMemberRecordExample> {
     @Autowired
     private ValidMemberRecordMapper validMemberRecordMapper;
    public int getNowCount(List<ValidMemberRecord> validMemberRecord) {

        AtomicInteger k = new AtomicInteger(0);
        validMemberRecord.forEach(s -> {
            if (s.getCount() > k.get()) {
                k.set(s.getCount());
            }
        });
        return k.get()+1;
    }

    public boolean checkNow(List<ValidMemberRecord> validMemberRecord, ValidConfig config) {
        for(ValidMemberRecord s:validMemberRecord){
            if(s.getConfigId().equals(config.getId())){
                return false;
            }
        }
        return true;
    }

    public ValidMemberRecord selectByMember(String memberId) {
        return validMemberRecordMapper.selectByMember(memberId, LocalDate.now(), Whether.NO.getDbIndex());
    }
}
